//
//  LYYWebviewViewController.m
//  Icar
//
//  Created by dllo on 15/10/20.
//  Copyright © 2015年 小龙侠. All rights reserved.
//

#import "LYYWebviewViewController.h"

@interface LYYWebviewViewController ()<UIWebViewDelegate>
@property (nonatomic,retain)NSURLRequest *request;
@property (nonatomic,retain)UIView *nightView;
@property (nonatomic,retain)UIWebView *webView;
@end

@implementation LYYWebviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[LYYNightModeHandle shareNightModeHandle].nightModeColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"<返回" style:UIBarButtonItemStylePlain target:self action:@selector(backToLastView)];
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH(375), SCREEN_HEIGHT)];
    [(UIScrollView *)[[self.webView subviews] objectAtIndex:0] setBounces:NO];
    if (self.model != nil) {
        NSString *url = [NSString stringWithFormat:@"http://mrobot.pcauto.com.cn/v2/bbs/topics/%ld?topicTemplate=4.5.0&picRule=2&authorId=0&pageNo=1",self.model.topicId];
        self.request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:url]];
    } else {
        NSString *url = [NSString stringWithFormat:@"http://mrobot.pcauto.com.cn/v2/bbs/topics/%ld?topicTemplate=4.5.0&picRule=2&authorId=0&pageNo=1",self.allModel.topicId];
        self.request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:url]];
    }
    [self.webView loadRequest:self.request];
    self.webView.scrollView.bounces = NO;
    self.webView.scalesPageToFit = YES;
   self.webView.delegate = self;
   [self.view addSubview:self.webView];

}


- (void)webViewDidFinishLoad:(UIWebView *)webView{
    if ([LYYNightModeHandle shareNightModeHandle].temp == YES) {
        [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'gray'"];
        [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#2E2E2E'"];
    }

}

- (void)viewWillAppear:(BOOL)animated{
    
    [self.webView reload];
}

- (void)backToLastView{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
